<?php
/**
 * @Entity
 * @Table(name="pizza")
 */
include "PizzaDefaultTopping.php";
class Pizza {



	/**
	 * @Id
	 * @Column(name="name", type="string", length=50, nullable=false)
	 */
	private $name;

	/**
	 * @Column(name="img", type="string", length=255, nullable=false)
	 */
	private $img;

	/**
	 * @Column(name="desc_long", type="clob", nullable=false)
	 */
	private $descLong;

	/**
	 * @Column(name="desc_short", type="clob", nullable=false)
	 */
	private $descShort;
	
	function Pizza($pizza){
		$this->setDescShort($pizza["desc_short"]);
		$this->setDescLong($pizza["desc_long"]);
		$this->setImg($pizza["img"]);
		$this->setName($pizza["name"]);
	}

	public function getName() 
	{
		return $this->name;
	} 

	public function setName($name) 
	{
		$this->name = $name;
	} 

	public function getImg() 
	{
		return $this->img;
	} 

	public function setImg($img) 
	{
		$this->img = $img;
	} 

	public function getDescLong() 
	{
		return $this->descLong;
	} 

	public function setDescLong($descLong) 
	{
		$this->descLong = $descLong;
	} 

	public function getDescShort() 
	{
		return $this->descShort;
	} 

	public function setDescShort($descShort) 
	{
		$this->descShort = $descShort;
	} 
	
	public function getSmallPrice($fp){
		if(!$fp){
			$price = 8.00;
		}else{
			$price = 4000;
		}
		$price += $this->priceToppings($fp);
		return $price;
	}
	
	public function getMediumPrice($fp){
		if(!$fp){
			$price = 11.00;
		}else{
			$price = 6000;
		}
		$price += $this->priceToppings($fp);
		return $price;
	}
	
	public function getLargePrice($fp){
		if(!$fp){
			$price = 14.00;
		}else{
			$price = 7500;
		}
		$price += $this->priceToppings($fp);
		return $price;
	}
	
	private function priceToppings($fp){
		$price = 0;
		$toppings = PizzaDefaultTopping::dbGetPizzaDefaultToppings("order_item_id = '".$this->getName()."'");
		if(!empty($toppings)){
			foreach($toppings as $topping){
				if(!$fp){
					$price += (0.5*$topping->getQuantity());
				}else{
					$price += (250*$topping->getQuantity());
				}
			}
		}
		return $price;
	}
	
	public static function dbGetPizzas($where){
		return dbGet("Pizza", "pizza", $where);
	}
	
	
	
}
?>